
{
    function getAge(dob) {
        var age=-1;
        try {
            var date1 = new Date();
            var convertedDob = dob.substring(5,7)+"/"+dob.substring(8,10)+"/"+dob.substring(0,4);
            var date2=new Date(convertedDob);
                
            var y1 = date1.getFullYear();
            var y2 = date2.getFullYear();
            if(y1>y2){
                var m1=date1.getMonth()+1;
                var m2=date2.getMonth()+1;
                if(m1>m2){
                    age=y1-y2;
                }else if(m1==m2){
                    var d1=date1.getDate();
                    var d2=date2.getDate();
                    if(d1>=d2){
                        age=y1-y2;
                    }else{
                        age=(y1-y2)-1;
                    }
                }else{
                    age=(y1-y2)-1;
                }
            }else{
                age=0;
            }
        }catch (Exception) {
            age =-1;
            document.write ("Error Message: Invalid date formate");
        } finally {
            return age;
        }
                
    }    
}